// pages/sharebox/relation/relation.js
var app = getApp();
var _PAGE = 1;
var _PAGESIZE = 10;
var load= true;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    id: 0,
    sharerList: [],
    hasMore: false,
    loading: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    that.setData({
      id: options.id
    })
    console.log(options.id)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    _PAGE = 1;
    that.getList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var that = this;
    if (!that.data.hasMore) {
      return false;
    }
    _PAGE++;
    that.setData({
      loading: true
    })
    that.getList();
  },

  addsharemsg() {
    var that = this;
    wx.navigateTo({
      url: '../myfamily/myfamily?id=' + that.data.id
    })
  },

  //是否共享
  sharefun(e) {
    var that = this;
    var shareid = e.currentTarget.dataset.id;
    var name = e.currentTarget.dataset.name;
    var aimg = e.currentTarget.dataset.aimg;
    var dname = e.currentTarget.dataset.dname;
    wx.navigateTo({
      url: '../shareFamily/shareFamily?id=' + that.data.id + '&shareid=' + shareid + '&name=' + name + '&aimg=' + aimg + '&dname=' + dname,
    })
  },

  // 获取共享列表
  getList() {
    var that = this;
    app.ajax({
      url: "User/Shared/SharerList",
      load:load,
      data: {
        page: _PAGE,
        row: _PAGESIZE,
        device_id: that.data.id
      },
      success: function(res) {
        if (res.data.code == 1000) {
          if (_PAGE == 1) {
            that.setData({
              sharerList: res.data.data.data
            })
          } else {
            that.setData({
              sharerList: that.data.sharerList.concat(res.data.data.data)
            })
          }
          // 是否加载更多
          var hasMore = true;
          if (res.data.data.data.length < _PAGESIZE) {
            hasMore = false;
          }
          that.setData({
            hasMore: hasMore,
            loading: false
          });
          load= false;
        } else {
          if (_PAGE == 1) {
            that.setData({
              hasMore: false,
              loading: false
            })
          } else {
            that.setData({
              hasMore: false,
              loading: false
            })
          }
        }
      }
    })
  }
})